﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WHControlLib.IconFont
{
    public partial class FontImageDesginFrm : Form
    {
        public FontImageDesginFrm()
        {
            InitializeComponent();
        }
        public int ReturnFontIndex { get; set; }
        Label labe;
        int SelectSymblo=-1;
        void lb1DoubleClick(object Sender,EventArgs e)
        {
            Label lb = (Label)Sender;
            ReturnFontIndex =(int) lb.Tag;
            SelectSymblo = ReturnFontIndex;
            DialogResult = DialogResult.OK;
            Close();

        }

        void lbOnMouseClick(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            pictureBox1.Image= FontImageHelper.GetImageFontBitmap((int)labe.Tag, Color.Red, 30);
            pictureBox1.Tag = (int)labe.Tag;
            SelectSymblo = (int)labe.Tag;
            label2.Text = "图标序号：" + labe.Tag.ToString();

        }
        void lbOnMouseEnter(object sender, EventArgs e)
        {
            Label lb = (Label)sender;
            lb.BackColor = Color.LightGoldenrodYellow;
            lb.BorderStyle = BorderStyle.FixedSingle;
            lb.Image = FontImageHelper.GetImageFontBitmap((int)lb.Tag, Color.DarkBlue,20);

            if (labe!=null)
            {
                labe.BackColor = Color.Transparent;
                labe.BorderStyle = BorderStyle.None;
                labe.Image = FontImageHelper.GetImageFontBitmap((int)labe.Tag, Color.Red, 15);

            }
            labe = lb;


        }
        
        private  void FontImageDesginFrm_Load(object sender, EventArgs e)
        {
            int count = FontImageHelper.ImageFontContainIntsList.Count;
           
      

             foreach (var item in FontImageHelper.ImageFontContainIntsList)
                {
                    Label lb1 = new Label();
                    lb1.Width = 40;
                    lb1.Height = 40;
                    string str = FontImageHelper.GetFontFromIntNumber(item);
                    lb1.Image = FontImageHelper.GetImageFontBitmap(str, Color.Red, 15);
                    toolTip1.SetToolTip(lb1, item.ToString());
                    lb1.Tag = item;
                    
                //Add Event
                lb1.DoubleClick += lb1DoubleClick;
                    lb1.MouseEnter += lbOnMouseEnter;
               
                     lb1.MouseClick+=lbOnMouseClick;    

                lb1.Padding = new Padding(2, 2, 2, 2);
                lb1.Margin=new Padding(2,2,2,2);
         
                flowLayoutPanel1.Controls.Add(lb1);

                }

            flowLayoutPanel1.Height = flowLayoutPanel1.Height + 20;
           flowLayoutPanel1.Focus();


        }

        private void flowLayoutPanel1_MouseLeave(object sender, EventArgs e)
        {
            if (labe != null)
            {
                labe.BackColor = Color.Transparent;
                labe.BorderStyle = BorderStyle.None;
                labe.Image = FontImageHelper.GetImageFontBitmap((int)labe.Tag, Color.Red, 15);

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            colorDialog1.ShowDialog();
            Color c = colorDialog1.Color;
            textBox1.BackColor = c;
            Color c2=DrawHelper.GetOppositeColor(c);

            textBox1.ForeColor = c2;
            int R = c2.R;
            int G = c2.G;
            int B = c2.B;
            textBox1.Text = "(" + R.ToString() + "," + G.ToString() + "," + B.ToString() + ")";
            pictureBox1.Image = FontImageHelper.GetImageFontBitmap((int)pictureBox1.Tag, c, 30);

           

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            if (SelectSymblo!=-1)
            {
            ReturnFontIndex = SelectSymblo;
            }
            
            Close();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
           
            Close();
        }



        //////////////////////////////////////////////////////////////////////

    }



}
